home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / fips11.zip / SOURCE / CMDL_ARG.CPP < prev    next >
C/C++ Source or Header  |  1994-05-25  |  5KB  |  129 lines

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module cmdl_arg.cpp
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/fips/source/main/RCS/cmdl_arg.cpp 1.1 1994/05/25 22:19:40 schaefer Exp schaefer $
  8.  
  9.     Copyright (C) 1993 Arno Schaefer
  10.  
  11.     This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation; either version 2 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU General Public License
  22.     along with this program; if not, write to the Free Software
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.  
  26.     Report problems and direct all questions to:
  27.  
  28.     schaefer@rbg.informatik.th-darmstadt.de
  29. */
  30.  
  31. #include <stdio.h>
  32. #include <ctype.h>
  33. #include <string.h>
  34. #include <stdlib.h>
  35. #include "global.h"
  36.  
  37. /* ----------------------------------------------------------------------- */
  38. /* Replacement for atoi                                                    */
  39. /* ----------------------------------------------------------------------- */
  40.  
  41. static int atoint (char *string)
  42. {
  43.     long int value = 0;
  44.     while (isdigit (*string))
  45.     {
  46.         value = value * 10 + (*string - '0');
  47.         if (value > 32767) return (-1);
  48.         string++;
  49.     }
  50.     if (*string != '\0') return (-1);
  51.     return (int) value;
  52. }
  53.  
  54. /* ----------------------------------------------------------------------- */
  55. /* Usage instructions                                                      */
  56. /* ----------------------------------------------------------------------- */
  57.  
  58. static void usage (void)
  59. {
  60.     printf ("\nFIPS {[-t][-d][-h|-?][-d<num>][-p<num>][-c<num>][-o<error>]}:\n\n");
  61.     printf ("-t        : test mode (no writes to disk)\n");
  62.     printf ("-d        : debug mode\n");
  63.     printf ("-h/-?     : this help page\n");
  64.     printf ("-d<num>   : select drive <num>\n");
  65.     printf ("-p<num>   : select partition <num>\n");
  66.     printf ("-c<num>   : new start cylinder = <num>\n");
  67.     printf ("-o<error> : override error message\n\n");
  68.     printf ("where <error> is\n\n");
  69.     printf ("mb - more than one bootable partition\t");
  70.     printf ("bf - invalid bootable-flag\n");
  71.     printf ("lf - FAT too large\t\t\t");
  72.     printf ("sf - FAT too small\n");
  73.     printf ("md - wrong media descriptor byte\t");
  74.     printf ("re - rootdir entries not multiple of 16\n");
  75. }
  76.  
  77. /* ----------------------------------------------------------------------- */
  78. /* Process commandline parameters                                          */
  79. /* ----------------------------------------------------------------------- */
  80.  
  81. void evaluate_argument_vector (int argc,char *argv[])
  82. {
  83.     while (--argc > 0)
  84.     {
  85.         int switchar = (*++argv)[0];
  86.         char *sw = *argv + 1;
  87.  
  88.         if (switchar != '/' && switchar != '-') error ("Invalid Commandline Parameter: %s",*argv);
  89.  
  90.         else if (!strcmp (sw,"t") || !strcmp (sw,"test")) global.test_mode = true;
  91.         else if (!strcmp (sw,"d") || !strcmp (sw,"debug")) global.debug_mode = true;
  92.         else if (!strcmp (sw,"h") || !strcmp (sw,"help") || !strcmp (sw,"?"))
  93.         {
  94.             usage ();
  95.             exit (0);
  96.         }
  97.         else if (!strcmp (sw,"omb")) global.override_multiple_boot = true;
  98.         else if (!strcmp (sw,"obf")) global.override_bootable_flag = true;
  99.         else if (!strcmp (sw,"ore")) global.override_rootdir_entries = true;
  100.         else if (!strcmp (sw,"olf")) global.override_large_fat = true;
  101.         else if (!strcmp (sw,"osf")) global.override_small_fat = true;
  102.         else if (!strcmp (sw,"omd")) global.override_media_descriptor = true;
  103.  
  104.         else switch ((*argv)[1])
  105.         {
  106.             case 'd':
  107.             {
  108.                 if ((global.drive_number_cmdline = atoint (*argv + 2)) == -1) error ("Invalid Argument: %s",*argv);
  109.                 if ((global.drive_number_cmdline < 0x80) || (global.drive_number_cmdline > 0xff)) error ("Invalid Drive number: %d",global.drive_number_cmdline);
  110.                 break;
  111.             }
  112.             case 'p':
  113.             {
  114.                 if ((global.partition_number_cmdline = atoint (*argv + 2)) == -1) error ("Invalid Argument: %s",*argv);
  115.                 if ((global.partition_number_cmdline < 1) || (global.partition_number_cmdline > 4)) error ("Invalid Partition number: %d",global.partition_number_cmdline);
  116.                 break;
  117.             }
  118.             case 'c':
  119.             {
  120.                 int h = atoint (*argv + 2);
  121.                 if (h == -1) error ("Invalid Argument: %s",*argv);
  122.                 global.new_start_cylinder_cmdline = h;
  123.                 break;
  124.             }
  125.             default: error ("Invalid Commandline Parameter: %s",*argv);
  126.         }
  127.     }
  128. }
  129.